import { getAllBlogTypes } from '@/api/blog'

const state = {
  blogTypes: [],
  blogId: null
}

const mutations = {
  SET_BLOG_TYPES: (state, blogTypes) => {
    state.blogTypes = blogTypes
  },
  SET_BLOG_ID: (state, blogId) => {
    state.blogId = blogId
  }
}

const actions = {
  async getBlogTypes({ commit }) {
    const res = await getAllBlogTypes()
    if (res.code === 200) {
      const { blogTypes } = res.data
      commit('SET_BLOG_TYPES', blogTypes)
      console.log(blogTypes)
    } else {
      console.log(res.message)
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
